package com.aspose.cells;

import java.util.ArrayList;

public class HeaderFooterCommand {
   private int b;
   Font a;
   private String c;
   private static final com.aspose.cells.b.c.a.za d = new com.aspose.cells.b.c.a.za(new String[]{"Bold", "加粗", "Italic", "倾斜", "Regular", "常规"});

   public int getType() {
      return this.b;
   }

   public Font getFont() {
      return this.a;
   }

   public String getText() {
      return this.c;
   }

   HeaderFooterCommand(int type, Font font, String text) {
      this.b = type;
      this.a = font;
      this.c = text;
   }

   static ArrayList a(Workbook var0, String var1) {
      Font var2 = null;
      boolean var3 = false;
      int var4 = 0;
      boolean var5 = false;
      boolean var6 = false;
      if (var1 != null && !"".equals(var1)) {
         ArrayList var7 = new ArrayList();

         int var8;
         for(var8 = 0; var8 < var1.length(); ++var8) {
            var3 = false;
            if (var1.charAt(var8) != '&') {
               var6 = false;
            } else if (var8 + 1 < var1.length()) {
               switch(var1.charAt(var8 + 1)) {
               case '"':
               case '1':
               case '2':
               case '3':
               case '4':
               case '5':
               case '6':
               case '7':
               case '8':
               case '9':
               case 'B':
               case 'E':
               case 'I':
               case 'K':
               case 'S':
               case 'U':
               case 'X':
               case 'Y':
                  var5 = true;
                  ++var8;
                  var3 = true;
                  break;
               case '#':
               case '$':
               case '%':
               case '\'':
               case '(':
               case ')':
               case '*':
               case '+':
               case ',':
               case '-':
               case '.':
               case '/':
               case '0':
               case ':':
               case ';':
               case '<':
               case '=':
               case '>':
               case '?':
               case '@':
               case 'C':
               case 'H':
               case 'J':
               case 'L':
               case 'M':
               case 'O':
               case 'Q':
               case 'R':
               case 'V':
               case 'W':
               default:
                  ++var8;
                  var3 = false;
                  var5 = false;
                  var6 = false;
                  break;
               case '&':
               case 'A':
               case 'D':
               case 'F':
               case 'G':
               case 'N':
               case 'P':
               case 'T':
               case 'Z':
                  ++var8;
                  var3 = true;
                  var5 = false;
                  var6 = false;
               }

               if (!var3) {
                  if (var8 - 1 > var4) {
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(0, var2, var1.substring(var4, var4 + (var8 - 1 - var4)))));
                     ++var8;
                     var4 = var8;
                  }
               } else {
                  if (var8 - 1 > var4) {
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(0, var2, var1.substring(var4, var4 + (var8 - 1 - var4)))));
                  }

                  if (var5) {
                     if (var2 == null) {
                        var2 = new Font(var0.getWorksheets(), (Object)null, false);
                        var2.c(var0.getWorksheets().G());
                     } else if (!var6) {
                        var2 = new Font(var0.getWorksheets(), (Object)null, false);
                        var2.c(var0.getWorksheets().G());
                     }

                     var6 = true;
                  }

                  switch(var1.charAt(var8)) {
                  case '"':
                     ++var8;

                     for(var4 = var8; var8 < var1.length() && var1.charAt(var8) != '"'; ++var8) {
                        ;
                     }

                     if (var8 - var4 >= 0) {
                        String var13 = var1.substring(var4, var4 + (var8 - var4));
                        a(var2, var13);
                     }
                     break;
                  case '#':
                  case '$':
                  case '%':
                  case '\'':
                  case '(':
                  case ')':
                  case '*':
                  case '+':
                  case ',':
                  case '-':
                  case '.':
                  case '/':
                  case '0':
                  case '1':
                  case '2':
                  case '3':
                  case '4':
                  case '5':
                  case '6':
                  case '7':
                  case '8':
                  case '9':
                  case ':':
                  case ';':
                  case '<':
                  case '=':
                  case '>':
                  case '?':
                  case '@':
                  case 'C':
                  case 'H':
                  case 'J':
                  case 'L':
                  case 'M':
                  case 'O':
                  case 'Q':
                  case 'R':
                  case 'V':
                  case 'W':
                  default:
                     for(var4 = var8++; var8 < var1.length() && Character.isDigit(var1.charAt(var8)); ++var8) {
                        ;
                     }

                     var2.setSize(com.aspose.cells.b.a.zo.a(var1.substring(var4, var4 + (var8 - var4))));
                     --var8;
                  case '&':
                     break;
                  case 'A':
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(5, var2, (String)null)));
                     break;
                  case 'B':
                     var2.setBold(true);
                     break;
                  case 'D':
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(3, var2, (String)null)));
                     break;
                  case 'E':
                     var2.setUnderline(2);
                     break;
                  case 'F':
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(6, var2, (String)null)));
                     break;
                  case 'G':
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(8, var2, (String)null)));
                     break;
                  case 'I':
                     var2.setItalic(true);
                     break;
                  case 'K':
                     if (var8 + 6 >= var1.length()) {
                        throw new CellsException(6, "Invalid font color of the page header/footer");
                     }

                     try {
                        int var9 = com.aspose.cells.b.a.zo.a(var1.substring(var8 + 1, var8 + 1 + 2), 515);
                        int var10 = com.aspose.cells.b.a.zo.a(var1.substring(var8 + 3, var8 + 3 + 2), 515);
                        int var11 = com.aspose.cells.b.a.zo.a(var1.substring(var8 + 5, var8 + 5 + 2), 515);
                        var2.setColor(Color.fromArgb(var9, var10, var11));
                     } catch (Exception var12) {
                        ;
                     }

                     var8 += 6;
                     break;
                  case 'N':
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(2, var2, (String)null)));
                     break;
                  case 'P':
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(1, var2, (String)null)));
                     break;
                  case 'S':
                     var2.setStrikeout(true);
                     break;
                  case 'T':
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(4, var2, (String)null)));
                     break;
                  case 'U':
                     var2.setUnderline(1);
                     break;
                  case 'X':
                     var2.setSuperscript(true);
                     break;
                  case 'Y':
                     var2.setSubscript(true);
                     break;
                  case 'Z':
                     com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(7, var2, (String)null)));
                  }

                  if (var1.charAt(var8) != '&') {
                     var4 = var8 + 1;
                  } else {
                     var4 = var8;
                  }
               }
            }
         }

         if (var8 > var4 && var4 < var1.length()) {
            com.aspose.cells.b.a.a.ze.a(var7, (Object)(new HeaderFooterCommand(0, var2, var1.substring(var4, var4 + (var8 - var4)))));
         }

         return var7;
      } else {
         return null;
      }
   }

   private static void a(Font var0, String var1) {
      int var2 = var1.indexOf(44);
      if (var2 == -1) {
         var0.b(var1);
      } else {
         var0.b(var1.substring(0, 0 + var2));
         var1 = var1.substring(var2 + 1);
         String[] var3 = com.aspose.cells.b.a.zv.d(var1, ' ');

         for(int var4 = 0; var4 < var3.length; ++var4) {
            switch(d.a(var3[var4])) {
            case 0:
            case 1:
               var0.setBold(true);
               break;
            case 2:
            case 3:
               var0.setItalic(true);
               break;
            case 4:
            case 5:
               var0.setItalic(false);
               var0.setBold(false);
            }
         }

      }
   }
}
